/*================================================================
*   File Name：common.c
*   Mail: a1277992967@163.com 
*   blog: http://www.ycst.club/suggest/ 
*   Author：ycst
*   Created Time：2022年08月15日 星期一 11时44分14秒
*   Describe：
*
================================================================*/

#include "../include/common.h"

int data_get_value(char* recv_, char *co_, int(* fun)(char *, char *)){
	return fun(recv_, co_);
}

int get_head(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	int d_id = 0, d_type = 0;
	double hum = 0, temp = 0;
	sscanf(recv, "%s %d %d %lf %lf %s", a, &d_id, &d_type, &hum, &temp, b);
	strcpy(co, a);
	return 0;
}
int get_device_id(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	char d_id[5] = {0};
	int d_type = 0;
	double hum = 0, temp = 0;
	sscanf(recv, "%s %s %d %lf %lf %s", a, d_id, &d_type, &hum, &temp, b);
	strcpy(co, d_id);
	return 0;
}
int get_device_type(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	char  d_type[10] = {0};
	int d_id = 0;
	double hum = 0, temp = 0;
	sscanf(recv, "%s %d %s %lf %lf %s", a, &d_id, d_type, &hum, &temp, b);
	strcpy(co, d_type);
	return 0;
}
int get_humidity(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	char hum[10] = {0};
	int d_id = 0, d_type = 0;
	double  temp = 0;
	sscanf(recv, "%s %d %d %s %lf %s", a, &d_id, &d_type, hum, &temp, b);
	strcpy(co, hum);
	return 0;
}
int get_temperature(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	char temp[10] = {0};
	int d_id = 0, d_type = 0;
	double hum = 0;
	sscanf(recv, "%s %d %d %lf %s %s", a, &d_id, &d_type, &hum, temp, b);
	strcpy(co, temp);
	return 0;
}
int get_FF(char *recv, char *co){
	char a[10] = {0};
	char b[5] = {0};
	int d_id = 0, d_type = 0;
	double hum = 0, temp = 0;
	sscanf(recv, "%s %d %d %lf %lf %s", a, &d_id, &d_type, &hum, &temp, b);
	if(strcmp(b, "FF") == 0)	return 0;
	return -1;
}





int cmd_get_value(char* recv_, char *co_, int(* fun)(char *, char *)){
	return fun(recv_, co_);
}




int cmd_get_head(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, head);
	return 0;
	
}
int cmd_get_device_id(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, device_id);
	return 0;
}
int cmd_get_device_type(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, device_id);
	return 0;
}
int cmd_get_major(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, major_cmd);
	return 0;
}
int cmd_get_min(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, min_cmd);
	return 0;
}
int cmd_get_result(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, cmd_result);
	return 0;
}

int cmd_get_FF(char *recv, char *co){
	char head[10] = {0};
	char device_id[5] = {0};
	char device_type[5] = {0};
	char major_cmd[10] = {0};
	
	char min_cmd[5] = {0};
	char cmd_result[5] = {0};
	char FF[5] = {0};
	sscanf(recv, "%s %s %s %s %s %s %s",head, device_id, device_type, major_cmd, min_cmd, cmd_result, FF);
	strcpy(co, FF);
	return 0;
}




